<template>
  <div>
    <!-- 搜索数据选择数据组件 -->
    <FaceuserinfoIndex
      v-if="showface"
      :option="optionList"
      :tableData="tableData"
      @faceuserinfo="faceuserinfo"
      @handleChange="handleCurrentChange"
      @getInfodata="getInfodata"
    />

    <!-- 客户信息组件 -->
    <FaceuserinfoTab
      v-if="showfaceinfo"
      :tableData="receiveInfo"
      @goback="goback"
      @initiatevideo="initiatevideo"
      @videoretrieve="videoretrieve"
      @faceuserinfosave="faceuserinfosave"
    />

    <!-- 视频答题组件 -->
    <Faceuservideo
      v-if="showfacevideo"
      :tableData="receiveInfo"
      @gobackvideo="gobackvideo"
    />

    <!-- 视频调阅组件 -->
    <Videoretrieve2
      v-if="showvideoretrieve"
      @gobackretrieve="gobackretrieve"
      :tableData="receiveInfo"
    />
  </div>
</template>

<script>
// import {} from "@/api/";
import FaceuserinfoIndex from "@/views/faceuserinfo/faceuserinfoIndex.vue";
import FaceuserinfoTab from "@/views/faceuserinfo/faceuserinfoTab.vue";
import Faceuservideo from "@/views/faceuserinfo/faceuservideo.vue";
import Videoretrieve2 from "@/views/faceuserinfo/videoretrieve2.vue";
import {
  queryInfofaceuserinfo,
  queryfaceuserinfosave
} from "@/api/hubeixiaojin/queryInfo";
export default {
  components: {
    FaceuserinfoIndex,
    FaceuserinfoTab,
    Faceuservideo,
    Videoretrieve2
  },

  data() {
    // 表单身份证
    var idcardReg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
    var validatePhone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("证件号不能为空!!"));
      }
      if (!idcardReg.test(value)) {
        callback(new Error("请输入正确的证件号码！"));
      } else {
        callback();
      }
    };
    return {
      showvideoretrieve: false, //默认不展示视频调阅页面
      showface: true, //默认展示数据页面
      showfaceinfo: false, //默认不展示客户信息页面
      showfacevideo: false, //默认不展示视频页面
      //客户信息
      tableData: {
        list: [],
        paging: true,
        page: {
          total: "",
          pageSize: 10,
          page: 1
        }
      },
      //表头
      optionList: [
        {
          label: "客户申请编号",
          prop: "applCde"
        },
        {
          label: "客户证件号码",
          prop: "idNo"
        },
        {
          label: "客户名称",
          prop: "custName"
        },
        {
          label: "贷款申请金额",
          prop: "applyAmt"
        },
        {
          label: "贷款期限",
          prop: "applyTnr"
        },
        {
          label: "门店",
          prop: "cooprName"
        },
        {
          label: "申请类型", //没找到
          prop: "wfiIntoPiecesMarked"
        },
        {
          label: "进件通道",
          prop: "docChannel"
        },
        {
          label: "申请日期",
          prop: "applyDt"
        },
        {
          label: "持续时长/进件时长",
          prop: "durationShow"
        },
        {
          label: "申请状态",
          prop: "wfiStatus"
        },
        {
          label: "是否挂起",
          prop: "suspendInd"
        },
        {
          label: "办理人",
          prop: "agentName"
        },
        {
          label: "调单指定人",
          prop: "dispatchingPerson"
        },
        {
          label: "营销中心",
          prop: "marketingCenter"
        }
      ],
      //选择的待面签审核信息
      receiveInfo: {},
      formInline: {
        custName: "",
        idNo: "",
        applCde: ""
      },
      agentInfo: {
        //当前座席名字和id
        // dispatchingPerson: Constants.Agent.agentName,
        // dispatchingId: Constants.Agent.agentId,
        // //目标座席和id
        // agentId: "",
        // agentName: "",
        // //座席行政组
        // deptGroupName: Constants.Agent.deptGroupName,
        // //行政组code
        // deptGroupCode: Constants.Agent.deptGroupCode,
        // //access_token
        // access_token: Constants.Agent.access_token,
        // //tenantId
        // tenantId: Constants.Agent.tenantId,
        // //orgCode
        // orgCode: Constants.Agent.orgCode
      } //调单用到的座席信息
    };
  },
  mounted() {
    const sessionStr = sessionStorage.getItem("userInfo");
    const agentUser = JSON.parse(sessionStr);
    this.agentInfo = agentUser.content;
    this.getInfo();
  },
  methods: {
    //首页数据
    getInfo() {
      // console.log("当前登录座席==", this.agentInfo);
      var params = {
        page: this.tableData.page.page, //翻页当前页码
        pageSize: this.tableData.page.pageSize, //翻页一次显示数量
        sortCol: "id",
        condition: {
          status: "1,2,3,10",
          // pushStatus: false,  //是否查核心
          custName: this.formInline.custName, //客户姓名
          idNo: this.formInline.idNo, //身份证
          applCde: this.formInline.applCde, // 申请编号
          agentId: this.agentInfo.agentId //当前登录座席
        } //申请状态
      };
      queryInfofaceuserinfo(params, this.agentInfo)
        .then(res => {
          // console.log("收到返回的调单面签信息=", res);
          if (res.data.retCode === 200) {
            this.tableData.list = res.data.data.listData; //数据
            this.tableData.page.total = res.data.data.totalCount; //总笔数
          } else {
            // console.log(res.msg);
            window.globalUiKit.notify("提示", "未查询到面签信息", "info");
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    faceuserinfo(val) {
      // console.log("触发面签", val);
      this.receiveInfo = val[0];
      this.showface = false;
      this.showfaceinfo = true;
    },
    handleCurrentChange(val) {
      console.log("触发handleCurrentChange,分页", val);
      this.tableData.page.page = val;
      this.getInfo();
    },
    getInfodata(val) {
      console.log("查询信息", val);
      this.formInline = val;
      this.tableData.page.page = 1;
      this.getInfo();
    },
    goback() {
      //返回数据搜索页
      this.showface = true;
      this.showfaceinfo = false;
      this.getInfo();
    },
    gobackvideo() {
      //视频页面返回主页
      this.showfacevideo = false;
      this.showface = false;
      this.showfaceinfo = true;
    },
    //发起视频切换页面
    initiatevideo(val) {
      console.log("接收到发起视频,userid==", val);
      this.receiveInfo.userid = val;
      this.showface = false;
      this.showfaceinfo = false;
      this.showfacevideo = true;
    },
    //面签信息保存
    faceuserinfosave(val) {
      console.log("保存面签信息=", val);

      var params = {
        condition: val,
        ids: [val.id],
        sortCol: "id"
      };

      queryfaceuserinfosave(params, this.agentInfo)
        .then(res => {
          if (res.data.retCode === 200) {
            console.log("保存面签信息接口返回=", res);
            window.globalUiKit.notify("提示", "保存面签信息成功", "info");
          } else {
            // console.log(res.msg);
            window.globalUiKit.notify("提示", "保存面签信息失败", "info");
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    //切换视频调阅
    videoretrieve() {
      console.log("接收到视频调阅");
      this.showface = false;
      this.showfaceinfo = false;
      this.showfacevideo = false;
      this.showvideoretrieve = true;
    },
    //视频调阅切回首页
    gobackretrieve() {
      this.showface = false;
      this.showfaceinfo = true;
      this.showfacevideo = false;
      this.showvideoretrieve = false;
    }
  }
};
</script>

<style>
.form-inline {
  /* display: flex; */
  /* justify-content: space-between; */
  /* margin-bottom: 20px; */
}
.Search {
  width: 100%;
  text-align: center;
}
.AdjustInput {
  display: flex;
  justify-content: end;
}
</style>
